package com.hyf.okhttp3demo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;

import com.hyf.okhttp3demo.activity.DownLoadFileActivity;
import com.hyf.okhttp3demo.activity.GetRequestActivity;
import com.hyf.okhttp3demo.activity.InterceptorActivity;
import com.hyf.okhttp3demo.activity.PostFileActivity;
import com.hyf.okhttp3demo.activity.PostJsonActivity;
import com.hyf.okhttp3demo.activity.PostRequestActivity;
import com.hyf.okhttp3demo.support.Item;
import com.hyf.okhttp3demo.support.MainListAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListView mListView;
    private List<Item> datas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView = (ListView) findViewById(R.id.lv_main);
        datas = new ArrayList<>();
        MainListAdapter adapter = new MainListAdapter(datas, this);
        mListView.setAdapter(adapter);
        initData();
        adapter.notifyDataSetChanged();
    }

    private void initData() {
        datas.add(new Item("get请求", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, GetRequestActivity.class));
            }
        }));

        datas.add(new Item("post请求", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, PostRequestActivity.class));
            }
        }));


        datas.add(new Item("PostJSON请求", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, PostJsonActivity.class));
            }
        }));

        datas.add(new Item("文件上传", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, PostFileActivity.class));
            }
        }));

        datas.add(new Item("下载文件", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, DownLoadFileActivity.class));
            }
        }));

        datas.add(new Item("拦截器实现下载监听", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, InterceptorActivity.class));
            }
        }));
    }
}
